<?php
	class ResponsesController extends  AppController{
		var $name = 'Responses';
		
		function get($postId = null){
			$this->layout = null;			
			$this->loadModel('User');
			$this->loadModel('Response');
			$this->Response->bindModel(array('belongsTo'=>array('User'=>array('className='=>'User','foreignKey'=>'users_id'))));
			$this->loadModel('Post');
			$postInfo = $this->Post->find('first',array(
				'conditions'=>array('Post.id'=>$postId) ,
				'fields'=>array('Post.reblog_posts_id')));
			$responses = null ;
			if(!empty($postInfo['Post']['reblog_posts_id'])){				
				$responses = $this->Response->find('all',array(
					'conditions'=>array('Response.posts_id'=>$postInfo['Post']['reblog_posts_id']),
						'fields'=>array('Response.id','Response.type','User.username')
				));
			}else{
				$responses = $this->Response->find('all',array(
						'conditions'=>array(
							'Response.posts_id'=>$postId
							),
							'fields'=>array('Response.id','Response.type','User.username')
				));
			}
			$this->set('responses',$responses);
		}
	}
?>